import { CoolController, BaseController } from '@cool-midway/core';
import { CircleEntity } from '../../entity/circle';
import { UserEntity } from '../../entity/user';
import { FollowsEntity } from '../../entity/follows';
import { ArticlesEntity } from '../../entity/articles';

/**
 * 圈子
 */
@CoolController({
  api: ['add', 'delete', 'update', 'info', 'list', 'page'],
  entity: CircleEntity,
  // 分页查询配置
  pageQueryOp: {
    // 模糊查询字段
    keyWordLikeFields: ['name'],
    select: ['a.*', 'b.name as userName', 'c.id as followId', 'd.id as articleId'],
    // 关联查询
    join: [
      {
        entity: UserEntity,
        alias: 'b',
        condition: 'a.openid = b.openid',
        type: 'leftJoin',
      },
      {
        entity: FollowsEntity,
        alias: 'c',
        condition: 'a.id = c.followId and c.type = 0',
        type: 'leftJoin',
      },
      {
        entity: ArticlesEntity,
        alias: 'd',
        condition: 'a.id = d.circleId',
        type: 'leftJoin',
      }
    ],
    // 添加排序
    addOrderBy: {
      id: 'asc'
    }
  }
})
export class CircleController extends BaseController {

}
